home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1158.ASC < prev    next >
Text File  |  1992-11-11  |  15KB  |  595 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                        PAGE  :  1/9
  12.  
  13.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  14.  
  15.  
  16.  
  17.  
  18.  
  19.        The following code provides an example of executing a Modal
  20.   Dialog Box from another Dialog Box when using Turbo Vision.
  21.  
  22.  
  23.   /*********************************************************************\
  24.    * TEST.CPP                                                          *
  25.    *   This module contains the Turbo Vision application code to run   *
  26.    *   this example.  It sets up the necessary menus to bring up the   *
  27.    *   test module represented by this demo.                           *
  28.    *                                                                   *
  29.    * TEST MODULE for Dialog Example #3 : Creating a second modal dialog*
  30.    *   box from within a first.                                        *
  31.    *                                                                   *
  32.    *********************************************************************
  33.    *                                                                   *
  34.    * This code was written by Borland Technical Support.               *
  35.    * It is provided as is with no warranties expressed or implied.     *
  36.    *                                                                   *
  37.   \*********************************************************************/
  38.  
  39.   #define Uses_TRect
  40.   #define Uses_TKeys
  41.   #define Uses_TEvent
  42.   #define Uses_TDialog
  43.   #define Uses_TMenu
  44.   #define Uses_TMenuItem
  45.   #define Uses_TMenuBar
  46.   #define Uses_TDeskTop
  47.   #define Uses_TApplication
  48.   #include <tv.h>
  49.   #include <mem.h>
  50.  
  51.   #pragma hdrstop
  52.  
  53.   #include "cmds.h"
  54.   #include "mdlg.h"
  55.  
  56.  
  57.   class TTestApp : public TApplication
  58.   {
  59.  
  60.   public:
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                        PAGE  :  2/9
  78.  
  79.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  80.  
  81.  
  82.  
  83.  
  84.       TTestApp() : TApplication(),
  85.                    TProgInit( initStatusLine, initMenuBar, initDeskTop )
  86.   { }
  87.       static TMenuBar *initMenuBar( TRect r );
  88.       virtual void handleEvent( TEvent& event );
  89.  
  90.   };
  91.  
  92.  
  93.   TMenuBar *TTestApp::initMenuBar( TRect r )
  94.   {
  95.       r.b.y = r.a.y + 1;
  96.       return new TMenuBar( r, new TMenu(
  97.           *new TMenuItem( "~D~ialog Box", cmEDialog, kbAltE )
  98.           ));
  99.   }
  100.  
  101.  
  102.   void TTestApp::handleEvent( TEvent& event )
  103.   {
  104.       TFirstDialog *td;
  105.  
  106.       TApplication::handleEvent( event );
  107.  
  108.       if( event.what == evCommand &&
  109.           event.message.command == cmEDialog )
  110.       {
  111.           td = new TFirstDialog( TRect(0,0,40,11),
  112.                                  "The first dialog box." );
  113.           if( validView( td ) )
  114.               deskTop->execView( td );
  115.       }
  116.   }
  117.  
  118.  
  119.   int main()
  120.   {
  121.       TTestApp TB;
  122.       TB.run();
  123.       return 0;
  124.   }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                        PAGE  :  3/9
  144.  
  145.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  146.  
  147.  
  148.  
  149.  
  150.   /*********************************************************************
  151.    *                                                                   *
  152.    * MDLG.CPP                                                          *
  153.    *   This module contains the code for the two subclassed dialogs use*
  154.    *   by this demo.                                                   *
  155.    *                                                                   *
  156.    * SUPPORT MODULE for dialog example #3 : Creating a second modal    *
  157.    *   dialog box from within a first.                                 *
  158.    *                                                                   *
  159.    *   The key to this operation is making sure that the deskTop's     *
  160.    *   execView() function is used in all cases when a modal dialog box*
  161.    *   is desired.  execView() is a member function of TGroup, thus any*
  162.    *   class derived from TGroup will have its own version of that     *
  163.    *   function.  When inside a dialog box handleEvent procedure, code *
  164.    *   such as                                                         *
  165.    *                                                                   *
  166.    *      TDialog *td = ...                                            *
  167.    *      execView( td );                                              *
  168.    *                                                                   *
  169.    *   will compile, but the box will come up with lots of flashing    *
  170.    *   white on red colors.  This is because the new dialog box was    *
  171.    *   inserted into the old dialog box, instead of the deskTop and the*
  172.    *   palette isn't mapped right.  The solution is to execView the    *
  173.    *   dialog box this way:                                            *
  174.    *                                                                   *
  175.    *      TDialog *td = ...                                            *
  176.    *      TProgram::deskTop->execView( td );                           *
  177.    *                                                                   *
  178.    *  'deskTop' is a static public member of TProgram and points to the*
  179.    *   desktop object of the current application.  This way, the dialog*
  180.    *   box will be inserted into the desktop and the palettes will work*
  181.    *   properly.  The Z order will also be correct so that the views   *
  182.    *   stack up right.                                                 *
  183.    *                                                                   *
  184.    *********************************************************************
  185.    *                                                                   *
  186.    * This code was written by Borland Technical Support.               *
  187.    * It is provided as is with no warranties expressed or implied.     *
  188.    *                                                                   *
  189.    *********************************************************************/
  190.  
  191.   #define Uses_TRect
  192.   #define Uses_TKeys
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  207.   VERSION  :  3.1
  208.        OS  :  DOS
  209.      DATE  :  November 11, 1992                        PAGE  :  4/9
  210.  
  211.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  212.  
  213.  
  214.  
  215.  
  216.   #define Uses_TEvent
  217.   #define Uses_TButton
  218.   #define Uses_TStaticText
  219.   #define Uses_TDialog
  220.   #define Uses_MsgBox
  221.   #define Uses_TDeskTop
  222.   #define Uses_TProgram
  223.   #include <tv.h>
  224.  
  225.   #pragma hdrstop
  226.  
  227.   #include "cmds.h"
  228.   #include "mdlg.h"
  229.  
  230.  
  231.   /********************************************************************
  232.    *   Class TFirstDialog                                             *
  233.    ********************************************************************
  234.    * TFirstDialog::TFirstDialog                                       *
  235.    *   Constructor for the dialog box.  Encapsulates the box to ease  *
  236.    *   creation.                                                      *
  237.    ********************************************************************/
  238.  
  239.   TFirstDialog::TFirstDialog( TRect& r, char *aTitle ) :
  240.       TDialog( r, aTitle ),
  241.       TWindowInit( initFrame )
  242.   {
  243.       insert( new TStaticText( TRect(2,2,38,6),
  244.          "This is a modal dialog box.  Hitting the <More> button below "
  245.          "will bring up a second modal dialog box on top of this one."
  246.           ));
  247.  
  248.       insert( new TButton( TRect(2,8,12,10),
  249.                           "~M~ore", cmMore, bfDefault )
  250.             );
  251.       insert( new TButton( TRect(14,8,24,10), "O~K~", cmOK, bfNormal )
  252.             );
  253.       insert( new TButton( TRect(26,8,36,10), "~C~ancel", cmCancel,
  254.                            bfNormal )
  255.             );
  256.  
  257.       selectNext( False );
  258.       options |= ofCentered;
  259.  
  260.